home *** CD-ROM | disk | FTP | other *** search
- class BuildingHandler
- {
- var location;
- var oHandler;
- var aPower;
- var aBuild;
- var oWorld;
- var nPowerMod;
- var cPowerChance;
- var tileBottomPlacement;
- var tileMidPlacement;
- var tileTopPlacement;
- var nArrayLimit;
- var oGerms;
- static var tileWidth;
- static var home;
- static var tileWidthBot;
- static var leftEdge;
- static var topEdge;
- static var tileHeightBot;
- static var tileHeightMid;
- static var tileHeightTop;
- static var floor;
- static var ceiling;
- static var homeLimit;
- static var tileWidthTop;
- static var tileWidthMid;
- var bAdd = false;
- var nGermChance = 5;
- var nTypes = 3;
- var nTotalGerms = 0;
- var critterFreq = 5;
- var maxCritters = 5;
- var cCritters = 0;
- var swingChance = 2;
- var bCheckPossible = false;
- var nPowerChance = 3;
- function BuildingHandler(loc)
- {
- this.location = loc;
- this.oHandler = new smashing.ClipHandler(this.location);
- this.aPower = ["BonusHang","BonusTime","BonusSpeed","BonusCoin"];
- }
- function update(nElapsed)
- {
- var _loc3_ = this.oHandler.clips;
- var _loc4_ = _loc3_.length;
- var _loc2_ = 0;
- while(_loc2_ < _loc4_)
- {
- _loc3_[_loc2_].render();
- _loc2_ = _loc2_ + 1;
- }
- if(this.bAdd == true)
- {
- this.addBuilding();
- }
- }
- function render()
- {
- var _loc8_ = smashing.Viewport.x + smashing.Viewport.halfWidth;
- var _loc9_ = _loc8_ - smashing.Viewport.width;
- var _loc5_ = Math.floor(_loc8_ / BuildingHandler.tileWidth) + 1;
- var _loc7_ = Math.floor(_loc9_ / BuildingHandler.tileWidth);
- if(_loc5_ > this.aBuild.length)
- {
- this.addBuilding(this.oWorld.level);
- }
- var _loc3_ = undefined;
- var _loc2_ = _loc7_;
- while(_loc2_ < _loc5_)
- {
- _loc3_ = this.aBuild[_loc2_];
- if(_loc3_.bOnStage == false)
- {
- this.buildOnStage(_loc3_);
- }
- _loc2_ = _loc2_ + 1;
- }
- var _loc4_ = this.oHandler.clips;
- var _loc6_ = _loc4_.length;
- _loc2_ = 0;
- while(_loc2_ < _loc6_)
- {
- _loc4_[_loc2_].render();
- _loc2_ = _loc2_ + 1;
- }
- }
- function reset(nLevel)
- {
- this.nPowerMod = this.nPowerChance + nLevel;
- this.cPowerChance = this.nPowerMod;
- this.cCritters = 0;
- this.oHandler.removeAllClips();
- BuildingHandler.home = null;
- this.aBuild = [];
- this.init();
- }
- function init()
- {
- BuildingHandler.tileWidth = BuildingHandler.tileWidthBot;
- BuildingHandler.leftEdge = - (smashing.Viewport.halfWidth + BuildingHandler.tileWidth);
- BuildingHandler.topEdge = - smashing.Viewport.halfHeight;
- this.tileBottomPlacement = smashing.Viewport.height - BuildingHandler.tileHeightBot;
- this.tileMidPlacement = this.tileBottomPlacement - BuildingHandler.tileHeightMid;
- this.tileTopPlacement = this.tileMidPlacement - BuildingHandler.tileHeightTop;
- BuildingHandler.floor = this.tileBottomPlacement + BuildingHandler.tileHeightBot + 50;
- BuildingHandler.ceiling = smashing.Viewport.height - BuildingHandler.tileHeightBot - BuildingHandler.tileHeightMid - BuildingHandler.tileHeightTop;
- this.addBuilding(this.oWorld.level,false);
- this.addBuilding(this.oWorld.level,false);
- this.addBuilding(this.oWorld.level);
- this.addBuilding(this.oWorld.level);
- this.render();
- this.nArrayLimit = Math.ceil(this.oWorld.nDist / BuildingHandler.tileWidth);
- }
- function removeBuilding(o, remove)
- {
- if(o.mcGerm != null)
- {
- _global.mcRoot.mcMenu.setUnFlash(o.mcGerm.sCrit);
- o.mcGerm.handler.removeClip(o.mcGerm);
- }
- o.oData.bOnStage = false;
- this.oHandler.removeClip(o);
- }
- function addBuilding(nLevel, bObst)
- {
- if(BuildingHandler.home != null)
- {
- return undefined;
- }
- var _loc2_ = new BData();
- _loc2_.nType = Math.ceil(Math.random() * this.nTypes);
- _loc2_.nLevel = (nLevel - 1) % 3;
- if(bObst == undefined)
- {
- bObst = smashing.Misc.rndBool();
- if(bObst == false)
- {
- _loc2_.bObstBot = false;
- _loc2_.sPowerupBot = this.shouldAddPowerup();
- }
- else
- {
- _loc2_.bObstBot = true;
- }
- }
- else
- {
- _loc2_.sPowerupBot = null;
- _loc2_.bObstBot = false;
- }
- if(smashing.Misc.rndBool())
- {
- _loc2_.bObstMid = true;
- }
- else
- {
- _loc2_.bObstMid = false;
- _loc2_.sPowerupMid = this.shouldAddPowerup();
- }
- if(smashing.Misc.rndBool())
- {
- _loc2_.bObstTop = true;
- }
- else
- {
- _loc2_.bObstTop = false;
- _loc2_.sPowerupTop = this.shouldAddPowerup();
- }
- _loc2_.x = this.aBuild.length * BuildingHandler.tileWidth;
- var _loc5_ = this.aBuild.length;
- var _loc3_ = undefined;
- if(_loc5_ > 0 && _loc5_ % this.critterFreq == 0 && this.cCritters < this.maxCritters)
- {
- this.cCritters = this.cCritters + 1;
- var _loc8_ = Math.floor(_loc5_ / this.critterFreq);
- var _loc10_ = this.oWorld.aPlacement[_loc8_ - 1];
- var _loc6_ = this.oWorld.aCritterList[_loc8_ - 1];
- if(_loc6_ != "sloth")
- {
- switch(_loc10_)
- {
- case 0:
- _loc2_.sCritBot = _loc6_;
- _loc2_.bObstBot = true;
- _loc2_.sPowerupBot = null;
- break;
- case 1:
- _loc2_.sCritMid = _loc6_;
- _loc2_.bObstMid = true;
- _loc2_.sPowerupMid = null;
- break;
- case 2:
- _loc2_.sCritTop = _loc6_;
- _loc2_.bObstTop = true;
- _loc2_.sPowerupTop = null;
- }
- }
- else
- {
- _loc2_.sCritTop = _loc6_;
- _loc2_.bObstTop = true;
- _loc2_.sPowerupTop = null;
- }
- }
- else if(_loc5_ > 4)
- {
- _loc3_ = this.aBuild[_loc5_ - 1];
- if(_loc3_.bObstMid && !_loc3_.bObstTop)
- {
- if(0 == Math.floor(Math.random() * this.swingChance))
- {
- _loc2_.sPowerupBot = null;
- _loc2_.bObstBot = false;
- _loc2_.sPowerupMid = null;
- _loc2_.bObstMid = false;
- _loc2_.sPowerupTop = null;
- _loc2_.bObstTop = false;
- _loc2_.bSwing = true;
- }
- }
- }
- _loc3_ = this.aBuild[_loc5_ - 1];
- if(this.aBuild.length > 2)
- {
- if(_loc2_.bSwing == false)
- {
- var _loc7_ = _loc2_.bObstBot + (_loc2_.bObstMid << 1) + (_loc2_.bObstTop << 2);
- if(_loc3_.bSwing == false)
- {
- var _loc4_ = _loc3_.bObstBot + (_loc3_.bObstMid << 1) + (_loc3_.bObstTop << 2);
- switch(_loc7_)
- {
- case 0:
- case 3:
- case 7:
- case 1:
- break;
- case 2:
- if(_loc4_ == 0)
- {
- _loc2_.bObstBot = true;
- _loc2_.sPowerupBot = null;
- }
- break;
- case 4:
- if(_loc4_ == 0)
- {
- _loc2_.bObstMid = true;
- _loc2_.sPowerupMid = null;
- _loc2_.bObstBot = true;
- _loc2_.sPowerupBot = null;
- }
- else if(_loc4_ == 1)
- {
- _loc2_.bObstMid = true;
- _loc2_.sPowerupMid = null;
- }
- break;
- case 5:
- if(_loc4_ == 0)
- {
- _loc2_.bObstMid = true;
- _loc2_.sPowerupMid = null;
- }
- else if(_loc4_ == 1)
- {
- _loc2_.bObstMid = true;
- _loc2_.sPowerupMid = null;
- }
- break;
- case 6:
- if(_loc4_ == 0)
- {
- _loc2_.bObstBot = true;
- _loc2_.sPowerupBot = null;
- }
- }
- }
- else
- {
- switch(_loc7_)
- {
- case 5:
- case 4:
- case 0:
- case 1:
- _loc2_.bObstMid = true;
- _loc2_.sPowerupMid = null;
- }
- }
- }
- }
- else if(this.aBuild.length == 2)
- {
- if(_loc2_.bObstBot == false)
- {
- if(_loc2_.bObstMid || _loc2_.bObstTop)
- {
- if(_loc2_.bObstTop)
- {
- _loc2_.bObstMid = true;
- _loc2_.sPowerupMid = null;
- }
- if(_loc2_.bObstMid)
- {
- _loc2_.bObstBot = true;
- _loc2_.sPowerupBot = null;
- }
- }
- }
- }
- this.aBuild.push(_loc2_);
- }
- function buildOnStage(oBuild)
- {
- oBuild.bOnStage = true;
- if(oBuild.bHome == false)
- {
- var _loc4_ = undefined;
- var _loc3_ = undefined;
- var _loc5_ = this.oHandler.addClip("mcTreeBottom0");
- _loc5_.x = oBuild.x;
- _loc5_.y = this.tileBottomPlacement;
- _loc5_.init(this,oBuild.bObstBot,oBuild.nType,oBuild,0);
- if(oBuild.sPowerupBot != null)
- {
- _loc4_ = this.oGerms.addGerm(_loc5_.x + _loc5_.mcBonusLoc._x,_loc5_.y + _loc5_.mcBonusLoc._y,oBuild.sPowerupBot);
- _loc4_.oData = oBuild;
- _loc4_.nSegment = 0;
- _loc4_.mcBuild = _loc5_;
- _loc5_.mcGerm = _loc4_;
- }
- else if(oBuild.sCritBot != undefined)
- {
- _loc3_ = this.oGerms.addGerm(_loc5_.x + _loc5_.gfx.mcGermPlacer._x,_loc5_.y + _loc5_.gfx.mcGermPlacer._y,"mcGerm");
- _loc3_.oData = oBuild;
- _loc3_.nSegment = 0;
- _loc3_.mcBuild = _loc5_;
- _loc3_.setCritter(oBuild.sCritBot);
- _loc3_.sCrit = oBuild.sCritBot;
- _loc5_.mcGerm = _loc3_;
- }
- _loc5_ = this.oHandler.addClip("mcTreeMiddle0");
- _loc5_.x = oBuild.x;
- _loc5_.y = this.tileMidPlacement;
- _loc5_.init(this,oBuild.bObstMid,oBuild.nType,oBuild,0);
- if(oBuild.sPowerupMid != null)
- {
- _loc4_ = this.oGerms.addGerm(_loc5_.x + _loc5_.mcBonusLoc._x,_loc5_.y + _loc5_.mcBonusLoc._y,oBuild.sPowerupMid);
- _loc4_.oData = oBuild;
- _loc4_.nSegment = 1;
- _loc4_.mcBuild = _loc5_;
- _loc5_.mcGerm = _loc4_;
- }
- else if(oBuild.sCritMid != undefined)
- {
- _loc3_ = this.oGerms.addGerm(_loc5_.x + _loc5_.gfx.mcGermPlacer._x,_loc5_.y + _loc5_.gfx.mcGermPlacer._y,"mcGerm");
- _loc3_.oData = oBuild;
- _loc3_.nSegment = 1;
- _loc3_.mcBuild = _loc5_;
- _loc3_.setCritter(oBuild.sCritMid);
- _loc3_.sCrit = oBuild.sCritMid;
- _loc5_.mcGerm = _loc3_;
- }
- _loc5_ = this.oHandler.addClip("mcTreeTop0");
- _loc5_.x = oBuild.x;
- _loc5_.y = this.tileTopPlacement;
- _loc5_.init(this,oBuild.bObstTop,oBuild.nType,oBuild,0);
- if(oBuild.sPowerupTop != null)
- {
- _loc4_ = this.oGerms.addGerm(_loc5_.x + _loc5_.mcBonusLoc._x,_loc5_.y + _loc5_.mcBonusLoc._y,oBuild.sPowerupTop);
- _loc4_.oData = oBuild;
- _loc4_.nSegment = 2;
- _loc4_.mcBuild = _loc5_;
- _loc5_.mcGerm = _loc4_;
- }
- else if(oBuild.sCritTop != undefined)
- {
- _loc3_ = this.oGerms.addGerm(_loc5_.x + _loc5_.gfx.mcGermPlacer._x,_loc5_.y + _loc5_.gfx.mcGermPlacer._y,"mcGerm");
- _loc3_.oData = oBuild;
- _loc3_.nSegment = 2;
- _loc3_.mcBuild = _loc5_;
- _loc3_.setCritter(oBuild.sCritTop);
- _loc3_.sCrit = oBuild.sCritTop;
- _loc5_.mcGerm = _loc3_;
- }
- if(oBuild.bSwing)
- {
- _loc4_ = this.oGerms.addGerm(_loc5_.x + _loc5_.mcBonusLoc._x,_loc5_.y + _loc5_.mcBonusLoc._y,"mcSwing");
- _loc5_.mcGerm = _loc4_;
- }
- }
- else
- {
- _loc5_ = this.oHandler.addClip("home");
- _loc5_.x = oBuild.x;
- _loc5_.y = BuildingHandler.floor - 50;
- BuildingHandler.homeLimit = _loc5_.x + BuildingHandler.tileWidth - smashing.Viewport.halfWidth;
- BuildingHandler.home = _loc5_;
- }
- }
- function addHome()
- {
- var _loc2_ = new BData();
- _loc2_.bHome = true;
- _loc2_.x = this.aBuild.length * BuildingHandler.tileWidth;
- this.aBuild.push(_loc2_);
- }
- function shouldAddGerm()
- {
- return 0 == Math.floor(Math.random() * this.nGermChance);
- }
- function shouldAddPowerup()
- {
- if(0 == Math.floor(Math.random() * this.cPowerChance))
- {
- this.cPowerChance = this.nPowerMod;
- var _loc2_ = this.aPower[Math.floor(Math.random() * this.aPower.length)];
- return _loc2_;
- }
- this.cPowerChance = this.cPowerChance - 1;
- return null;
- }
- }
-